package com.uniriho.lxr5002_key_switch_lh

import android.annotation.SuppressLint
import android.os.Bundle
import android.util.Log
import android.view.KeyEvent
import android.view.WindowManager
import androidx.activity.ComponentActivity
import com.sdk.devicemanager.DEVICEcon
import com.uniriho.lxr5002_key_switch_lh.databinding.ActivityMainBinding

class MainActivity : ComponentActivity() {

    private val mainDataBinding by lazy {
        ActivityMainBinding.inflate(layoutInflater)
    }

    private val mainMoudel by lazy {
        MainMoudel()
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
        super.onCreate(savedInstanceState)
        setContentView(mainDataBinding.root)
        val devicEcon = DEVICEcon(this)
        devicEcon.setNavigationMode("system_nav_gestural")
        devicEcon.setGestureModeBackEnable(false)
        mainMoudel.init(mainDataBinding,this)
        initEvent()
    }

    private fun initEvent() {
        mainDataBinding.btnExit.setOnClickListener { finish() }
    }


    @SuppressLint("RestrictedApi")
    override fun dispatchKeyEvent(event: KeyEvent?): Boolean {
        mainMoudel.disPatchEvent(event!!)
        return false
    }

    override fun onStop() {
        super.onStop()
        Log.e("life","onStop")
        mainMoudel.saveKeyCount(this)
    }
}

